home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / SAT 2.3.8 / Demos / StepPlatform Demo ƒ / sEmptyPlatform.p < prev    next >
Text File  |  1995-09-03  |  2KB  |  92 lines

  1. (* Platform sprite, experimental faceless sprite *)
  2.  
  3. unit sEmptyPlatform;
  4. interface
  5.     uses
  6. {$ifc UNDEFINED THINK_PASCAL}
  7.         Types, QuickDraw, Menus, Windows, TextEdit, Fonts, Dialogs, Memory, {}
  8. {$endc}
  9.         SAT, PlatformGlobals, sPlatForm, sPlayerSprite;
  10.  
  11.     procedure InitEmptyPlatform;
  12.     procedure SetupEmptyPlatform (me: SpritePtr);
  13.  
  14. implementation
  15.  
  16.     procedure InitEmptyPlatform;
  17. (* nada*)
  18.     begin
  19.     end;
  20.  
  21.     procedure SetupEmptyPlatform (me: SpritePtr);
  22.         var
  23.             r: Rect;
  24.             pol: PolyHandle;
  25.     begin
  26.         me^.task := @HandlePlatform;
  27.         me^.hitTask := @HitPlatform;
  28.  
  29.         me^.face := nil; (* = faceless! *)
  30.         SetRect(me^.hotRect, 0, 0, gSAT.offSizeH - 150, 16);
  31.  
  32.         me^.layer := -me^.position.v;
  33.     end;
  34.  
  35.     procedure HandleEmptyPlatform (me: SpritePtr);
  36.     (*me->face = nil;*)
  37.     begin
  38.     end;
  39.  
  40.     procedure HitEmptyPlatform (me: SpritePtr; him: PlSpritePtr);
  41.         var
  42.             mini, i, min: Integer;
  43.             diff: array[0..5] of Integer;
  44.     begin
  45.         if him^.task = @HandlePlayerSprite then
  46.             begin
  47.                 diff[1] := -me^.hotRect2.top + (him^.hotRect2.bottom);        (* TtoB *)
  48.                 diff[2] := -him^.hotRect2.top + (me^.hotRect2.bottom);         (* BtoT *)
  49.                 diff[3] := -me^.hotRect2.left + (him^.hotRect2.right);        (* LtoR *)
  50.                 diff[4] := -him^.hotRect2.left + (me^.hotRect2.right);        (* RtoL *)
  51.                 mini := 0;
  52.                 min := 10000;
  53.                 for i := 1 to 4 do
  54.                     begin
  55.                         if (min > diff[i]) then
  56.                             begin
  57.                                 min := diff[i];
  58.                                 mini := i;
  59.                             end; (* if *)
  60.                     end;
  61.                 case mini of
  62.                     1: (*floor*)
  63.                         begin
  64.                             him^.action := Stand;
  65.                             him^.position.v := him^.position.v - diff[1] + 1;
  66.                             if (him^.speed.v > 0) then
  67.                                 him^.speed.v := 0;
  68.                             him^.speed.h := 0;
  69.                         end;
  70.                     2: (* ceiling *)
  71.                         begin
  72.                             him^.position.v := him^.position.v + diff[2] + 1;
  73.                             if (him^.speed.v < 0) then
  74.                                 him^.speed.v := -him^.speed.v;
  75.                         end;
  76.                     3: (*left*)
  77.                         begin
  78.                             him^.position.h := him^.position.h - diff[3] - 1;
  79.                             if (him^.speed.h > 0) then
  80.                                 him^.speed.h := -him^.speed.h;
  81.                         end;
  82.                     4: (*right*)
  83.                         begin
  84.                             him^.position.h := him^.position.h + diff[4] + 1;
  85.                             if (him^.speed.h < 0) then
  86.                                 him^.speed.h := -him^.speed.h;
  87.                         end;
  88.                 end; (* switch *)
  89.             end;
  90.     end;
  91.  
  92. end.